﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;

namespace Himp.TaskScheduling
{
    /// <summary>
    /// 弃样服务
    /// </summary>
    public class SampleDiscardedTaskService : TaskSchedulingAppService, ISampleDiscardedTaskService
    {
        private IRepository<SampleTestTask, long> _sampleTestTaskRepository;

        public SampleDiscardedTaskService( IRepository<SampleTestTask, long> sampleTestTaskRepository)
        {
            _sampleTestTaskRepository = sampleTestTaskRepository;
        }

        /// <summary>
        /// 弃样
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<SampleTestTaskDto> Post(SampleDiscardedTaskCreateDto input)
        {
            SampleTestTask sampleTestTask = new SampleTestTask();
            sampleTestTask.SampleCode = "-";
            sampleTestTask.TestCode = "-";
            sampleTestTask.BottomCode = input.BottomCode;
            sampleTestTask.SampleType = "41";
            sampleTestTask.TestCnt = 0;
            sampleTestTask.TaskAssgnTime = DateTime.Now;
            sampleTestTask.LastOperTime = DateTime.Now;
            sampleTestTask.TestItems = "";
            sampleTestTask.ExecStas = "就绪";
            sampleTestTask.ManualFlag = input.ManualFlag;
            sampleTestTask = await _sampleTestTaskRepository.InsertAsync(sampleTestTask);
            var itemDto = ObjectMapper.Map<SampleTestTask, SampleTestTaskDto>(sampleTestTask);

            return itemDto;
        }
    }
}
